package com.zq.设计模式23种.创建型模式.工厂方法模式;

/**
 * @author Jiu  感觉比较搞笑
 * @description：实际使用场景:todo
 * @date 2020/11/25   11:53
 **/
public class FactoryMethed {

    public static void main(String[] args) {
        IFactory factory = new UndergraduateFactory();
        LeiFeng student = factory.CreateLeiFeng();

        student.Sweep();
        student.Wash();
        student.BuyRice();
        System.out.println("\n --------------------------");

        IFactory factory2 = new VolunteerFactory();
        LeiFeng volunteer = factory2.CreateLeiFeng();

        volunteer.Sweep();
        volunteer.Wash();
        volunteer.BuyRice();

    }


}

abstract class LeiFeng {
    public abstract void Sweep();
    public abstract void Wash();
    public abstract void BuyRice();
}

class Volunteer extends LeiFeng {
    @Override
    public void Sweep() {
        System.out.println("Volunteer Sweep");
    }
    @Override
    public void Wash() {
        System.out.println("Volunteer Wash");
    }
    @Override
    public void BuyRice() {
        System.out.println("Volunteer BuyRice");
    }
}

class Undergraduate extends LeiFeng {
    @Override
    public void Sweep() {
        System.out.println("Undergraduate--- Sweep");
    }
    @Override
    public void Wash() {
        System.out.println("Undergraduate--- Sweep");
    }
    @Override
    public void BuyRice() {
        System.out.println("Undergraduate--- Sweep");
    }
}


interface IFactory {
    LeiFeng CreateLeiFeng();
}

//社区志愿者工厂
class VolunteerFactory implements IFactory {
    @Override
    public LeiFeng CreateLeiFeng() {
        return new Volunteer();
    }
}

//学雷锋的大学生工厂
class UndergraduateFactory implements IFactory {
    @Override
    public LeiFeng CreateLeiFeng() {
        return new Undergraduate();
    }
}